package org.example.executor.testCpu;

import cn.hutool.core.thread.NamedThreadFactory;
import cn.hutool.core.thread.ThreadFactoryBuilder;
import org.example.executor.testRunnableAndThreadPool.MyRunnable;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author liyishan
 * @date 2024/12/20
 * @description
 */

public class Test01 {
    private static final int CORE_POOL_SIZE = 5;
    private static final int MAX_POOL_SIZE = 10;
    private static final int QUEUE_CAPACITY = 1;
    private static final Long KEEP_ALIVE_TIME = 1L;
    private static ThreadPoolExecutor executor = new ThreadPoolExecutor(
        CORE_POOL_SIZE,
        MAX_POOL_SIZE,
        KEEP_ALIVE_TIME,
        TimeUnit.SECONDS,
        new ArrayBlockingQueue<>(QUEUE_CAPACITY),
        new ThreadPoolExecutor.CallerRunsPolicy());
    public static void main(String[] args) {
        test();
    }

    public static void test00() {
        CustomThreadFactory threadFactory = new CustomThreadFactory("testThread-");
        for (int i = 0; i < 100; i++) {
            threadFactory.newThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(5000);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    }

    public static void test(){
        for(int i = 0;i<1000;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    while (true){}
                }
            },"testThread").start();
        }

    }



    public static void test1(){
        for(int i = 0;i<100;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try{
                        Thread.sleep(500000);
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            },"testThread").start();
        }
    }
}
